package com.fishery.logistics.controller;


import com.fishery.entity.Result;
import com.fishery.logistics.entity.Station;
import com.fishery.logistics.entity.vo.StationVo;
import com.fishery.logistics.service.StationService;
import com.fishery.logistics.utils.ConvertUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author run
 * @since 2021-01-23
 */
@Api(tags = "物流站点接口")
@CrossOrigin
@RestController
@RequestMapping("/logistics/station")
public class StationController {

    @Autowired
    private StationService stationService;

    @Autowired
    private ConvertUtil convertUtil;

    @PostMapping("/")
    @ApiOperation("创建物流站点")
    public Result createStation(@RequestBody @ApiParam(required = true,value = "stationVo") StationVo stationVo){
        return stationService.createStation(convertUtil.convert(stationVo,Station.class))
                ? Result.success("创建成功") : Result.error("创建失败");
    }

    @PutMapping("/")
    @ApiOperation("修改物流站点信息")
    public Result updateStation(@RequestBody @ApiParam(required = true,value = "stationVo") StationVo stationVo){
        return stationService.updateStation(convertUtil.convert(stationVo,Station.class))
                ? Result.success("修改成功") : Result.error("修改失败");
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除物流站点信息")
    public Result deleteStation(@PathVariable(value = "id") String stationId){
        return stationService.deleteStation(stationId)
                ? Result.success("删除成功") : Result.error("删除失败");
    }

    @GetMapping("/{id}")
    @ApiOperation("根据基地id获取该基地所管理的站点")
    public Result searchStationOfBase(@PathVariable(value = "id") String baseId){
        return Result.success().data(stationService.searchStationOfBase(baseId));
    }

    @GetMapping("/{id}/{page}/{size}")
    @ApiOperation("根据基地id分页获取物流站点")
    public Result searchStationOfBase(@PathVariable(value = "id") String baseId
                                    ,@PathVariable(value = "page") Integer page
                                    ,@PathVariable(value = "size") Integer size){
        return Result.success().data(stationService.searchStationOfBase(baseId,page,size));
    }
}

